package com.ych.coinsdkDemo;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.ArrayUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.ych.ytdevicesdk.BuildConfig;
import com.ych.ytdevicesdk.DeviceManager;
import com.ych.ytdevicesdk.IDeviceManager;
import com.ych.ytdevicesdk.entity.AppInfoEntity;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getPermission();

    }

    private void getPermission() {
        PermissionUtils.permission(PermissionConstants.PHONE, PermissionConstants.STORAGE).callback(new PermissionUtils.SimpleCallback() {
            @Override
            public void onGranted() {
                AppInfoEntity appInfoEntity = new AppInfoEntity();
                appInfoEntity.setDeviceType("Android");
                appInfoEntity.setAppTitle("android Test app");
                appInfoEntity.setSoftVer(BuildConfig.versionCode);
                DeviceManager.getInstance()
                        .debugger(true, true)
                        .logger(true)
                        .initSdk("odIsLCTgMEmrfGIkl24mwt", "AndrSdk_Test", appInfoEntity)
                        .setInitListener(new IDeviceManager.InitListener() {
                            @Override
                            public void registerFailed(long errorCode, String errorMsg) {
                                LogUtils.i(String.format("registerFailed errorCode : %s ; errorMsg : %s", errorCode, errorMsg));

                            }

                            @Override
                            public void needUpdate(String... updateAddress) {
                                LogUtils.i("needUpdate : " + ArrayUtils.toString(updateAddress));

                            }

                            @Override
                            public void bindStatus(boolean isSuccess) {
                                LogUtils.i("bindStatus : " + isSuccess);
                            }

                            @Override
                            public void onError(String type, long errorCode, String msg) {
                                LogUtils.i(String.format("onError type : %s ; errorCode : %s ; msg %s ", type, errorCode, msg));

                            }
                        })
                        .setEventListener(new IDeviceManager.IMqMessageListener() {
                            @Override
                            public void deviceBinding() {
                                LogUtils.i("deviceBinding");

                            }

                            @Override
                            public void deviceUnBinding() {
                                LogUtils.i("deviceUnBinding");

                            }

                            @Override
                            public void deviceReBoot() {
                                LogUtils.i("deviceReBoot");

                            }
                        });

            }

            @Override
            public void onDenied() {
                getPermission();
            }
        }).request();


    }
}